<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<style>

  /* 样式搜索框容器 */
  .search-container {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    background-color: #ffffff;
    border-radius: 5px 5px 0 0;
    border-bottom: 1px solid #ccc
  }

  /* 样式搜索框输入框 */
  .search-container input[type="text"] {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    margin: 20px 5px 10px 0;
  }

  /* 样式搜索按钮 */
  .search-container button {
    padding: 6px 12px;
    background-color: darkturquoise;
    color: white;
    border: 1px solid #4CAF50;
    border-radius: 4px;
    cursor: pointer;
  }

  /* 鼠标悬停时改变按钮背景色 */
  .search-container button:hover {
    background-color: #45a049;
  }

  .course-space {
    display: flex;
    flex-wrap: wrap;
    background-color: #ffffff;
    border-radius: 0 0 5px 5px;
    padding-bottom: 50px;
  }

  .course-card {
    padding: 20px;
    margin-left: 10px;
    margin-bottom: 20px;
    text-align: center;

    .cover {
      width: 250px;
      height: 140px;
      display: block;
      margin: 0 auto;
      border-radius: 5px;
    }

    .title {
      display: block;
      color: #000;
      font-weight: bold;
      margin-top: 10px;
    }

    .course-link:hover .title {
      color: darkturquoise;
      /* 鼠标移入时的标题颜色 */
    }
  }

</style>


<div class="search-container">
  <form action="/search" method="get" style="margin-right: 20px;">
    <input type="text" name="q" placeholder="请输入关键词...">
    <button type="submit" style="margin-top: 2px;">搜索</button>
  </form>
</div>
<div class="course-space">
  <c:forEach var="course" items="${courses_key}">
    <div class="course-card">
      <a href="javascript:void(0)" onclick="toMaterial('${course.id}')" class="course-link"
         style="text-decoration: none;">
        <img class="cover" alt="课程封面" src=${course.cover}>
        <span class="title">${course.title}</span>
      </a>
    </div>
  </c:forEach>
</div>

<script>
  function toMaterial(id) {
    var xhr = new XMLHttpRequest()
    xhr.open('GET', '/day_day_up/course?id=' + id)
    xhr.onreadystatechange = function () {
      if (xhr.readyState === 4 && xhr.status === 200) {
        window.open('/day_day_up/course/index.jsp?id=' + id, '_blank');
      }
    }
    xhr.send()
  }
</script>
